package objects.base;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.StateBasedGame;
import util.level.Room;

/**
 * This class holds some specific behaviour important
 * for falling objects to have.
 * 
 * @author John
 */

public class GravityObj extends Collidable
{
	protected static final float NORMAL_GRAVITY = 0.43f;
	
	/**
	 * Initializes a falling object of given size at the given position.
	 * 
	 * @param initX - The initial X position.
	 * @param initY - The initial Y position.
	 * @param initWidth - The initial width of the object.
	 * @param initHeight - The initial height of the object.
	 */
	public GravityObj(float initX, float initY, float initWidth, float initHeight)
	{
		super(initX, initY, initWidth, initHeight);
		// Give it the standard deceleration of gravity
		yMotion[0].acc = NORMAL_GRAVITY;
	}
	
	/**
	 * Adds in various speed changes made when collisions occur
	 * (ie when you're standing, you don't keep accelerating into
	 * the ground.)
	 * 
	 * @param gc {@inheritDoc}
	 * @param game {@inheritDoc}
	 */
	public void step(GameContainer gc,StateBasedGame sbg,Room room)
	{
		// Do movement
		super.step(gc,sbg,room);
		// If you hit the ceiling or floor, remove vertical speed
		if (vertStop[0] || vertStop[1])
		{
			for (int i = 0; i < vectorTotal; i++)
				yMotion[i].speed = 0;
		}
	}
}
